/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.ContentLanguageHeader;
import java.util.Locale;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class ContentLanguageHeaderImpl extends HeaderBase implements ContentLanguageHeader {
    private static final ContentLanguageHeaderParser parser = new ContentLanguageHeaderParser();

    private Locale contentLanguage;

    public ContentLanguageHeaderImpl() {
        super(ContentLanguageHeader.NAME);
    }

    public ContentLanguageHeaderImpl(byte[] data, int start, int end) {
        super(ContentLanguageHeader.NAME, data, start, end);
    }

    public Object clone() {
        final ContentLanguageHeaderImpl header = new ContentLanguageHeaderImpl();
        header.cloneBase(this);
        if (parsed){
            header.contentLanguage = this.contentLanguage;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        final StringBuilder sb = new StringBuilder(contentLanguage.getLanguage());
        final String country = contentLanguage.getCountry();
        if (country != null && !country.equals("")) sb.append('-').append(country.toLowerCase());
        return sb.toString();
    }

    /**
     * Gets the language value of the ContentLanguageHeader.
     *
     * @return the Locale value of this ContentLanguageHeader
     */
    public Locale getContentLanguage() {
        parse();
        return contentLanguage;
    }

    /**
     * Sets the language parameter of this ContentLanguageHeader.
     *
     * @param language the new Locale value of the language of
     *                 ContentLanguageHeader
     */
    public void setContentLanguage(Locale language) {
        parse();
        this.contentLanguage = language;
        invalidateHeaderData();
    }
}
/*
 * $Log$
 */